<?php 

$id = (int)$query_string[2];

$sql->mysql_select("quiz", "*","quiz_id = ".$id);
$quiz = $sql->get_line();

$sql->mysql_select("quiz_ittems","*","quiz_ittems_quiz = ".$id,"quiz_ittems_id ASC");
$quiz_ittems = $sql->get_table();

$sql->mysql_select("quiz_theme","*","","quiz_theme_name ASC");
$quiz_theme = $sql->get_table();

$sql->mysql_select("ertekelesek","*","","ertekelesek_name ASC");
$ertekelesek = $sql->get_table();

$ittem_id = -1;
$folder_files = array();

//$theme->footer_jssrc[] = "$('#sortable').sortable();";
//$theme->footer_jssrc[] = "$('#sortable').disableSelection();"; 


/*
print "<pre>";
print_r($quiz);
print_r($quiz_ittems);
print "</pre>";

/*
$form_value['action'] = "edit";
$form_value['module'] = "users.list";
$form_value['id'] = $id;

$page_title = "Felhasználó szerkesztése";
$page_text = $theme->show_form($module_db);
*/

$page_title = "Teszt szerkesztése";

$page_text = "
	<div class='admin_form ui-widget'>
		<form action='modules/quiz/quiz_action.php' method='post' enctype='multipart/form-data'>
			<input type='hidden' name='action' value='edit' />
			<input type='hidden' name='id' value='".$id."' />
			
			<div class='fieldset'>
				<div class='legend'><span class='left title'>Teszt címe:</span> <span class='ui-icon ui-icon-info help-box left' info-title='Teszt címe' info-text='".HELP_QUIZ_QUIZ_TITLE."'></span></div>
				<input class='text ui-widget-content ui-corner-all' type='text' name='quiz_title' maxlength='100' value='".$quiz['quiz_title']."' />
				
			</div>
			
			<div class='fieldset'>
				<div class='legend'><span class='left title'>Alapértelmezett teszt:</span> <span class='ui-icon ui-icon-info help-box left' info-title='Alapértelmezett teszt' info-text='".HELP_QUIZ_QUIZ_DEFAULT."'></span></div>
				<input class='ui-widget-content ui-corner-all' type='checkbox' ".($quiz['quiz_default']=="1"?"checked":"")." name='quiz_default' value='true' />
			</div>
			
			<div class='fieldset'>
				<div class='legend'><span class='left title'>Teszt leírása:</span> <span class='ui-icon ui-icon-info help-box left' info-title='Teszt leírása' info-text='".HELP_QUIZ_QUIZ_TEXT."'></span></div>
				<textarea class='textarea tinymce ui-widget-content ui-state-default ui-corner-all' name='quiz_text'>".$quiz['quiz_text']."</textarea>
			</div>
			
			<div class='fieldset'>
				<div class='legend'><span class='left title'>Teszt képe:</span> <span class='ui-icon ui-icon-info help-box left' info-title='Teszt képe' info-text='".HELP_QUIZ_QUIZ_IMAGE."'></span></div>
				<a id='news_image_link' href='".IMAGE_UPLOAD.$quiz['quiz_image']."' class='lightbox' ".(empty($quiz['quiz_image'])?"style='display:none'":"")."><img class='ui-corner-all' id='news_image' src='".IMAGE_UPLOAD.$quiz['quiz_image']."' width='100px'></a>
				<br />";
						
				if ($handle = opendir(IMAGE_UPLOAD)) 
				{
					$page_text .= "<select id='quiz_image_imagefile' name='quiz_image_imagefile' class='select ui-state-default ui-widget-content ui-corner-all' onChange=\"changeimage('quiz_image_imagefile','news_image')\" >
						<option value='none'>Feltöltés</option>";
				    while (false !== ($file = readdir($handle))) 
				    {
				    	if ($file<>"." && $file<>".." && !is_dir(IMAGE_UPLOAD."/".$file))
				    	{
				    		$page_text .= "<option ".($quiz['quiz_image']==$file?"selected":"")." value='".$file."'>".$file."</option>";
				    	}
				    }
				    $page_text .= "</select>";
		
				    closedir($handle);
				}
				
				$page_text .= "
				<input type='file' class='file ui-widget-content ui-state-default ui-corner-all' name='quiz_image_imageupload' />
			</div>
			
			<div class='fieldset'>
				<div class='legend'><span class='left title'>Poszt képe:</span> <span class='ui-icon ui-icon-info help-box left' info-title='Poszt képe' info-text='".HELP_QUIZ_QUIZ_POST."'></span></div>
				<a id='news_post_link' href='".IMAGE_POST_UPLOAD.$quiz['quiz_post']."' class='lightbox' ".(empty($quiz['quiz_post'])?"style='display:none'":"")."><img class='ui-corner-all' id='news_post' src='".IMAGE_POST_UPLOAD.$quiz['quiz_post']."' width='100px'></a>
				<br />";
						
				if ($handle = opendir(IMAGE_POST_UPLOAD)) 
				{
					$page_text .= "<select id='quiz_post_imagefile' name='quiz_post_imagefile' class='select ui-state-default ui-widget-content ui-corner-all' onChange=\"changeimage('quiz_post_imagefile','news_post','".IMAGE_POST_UPLOAD."')\" >
						<option value='none'>Feltöltés</option>";
				    while (false !== ($file = readdir($handle))) 
				    {
				    	if ($file<>"." && $file<>".." && !is_dir(IMAGE_POST_UPLOAD."/".$file))
				    	{
				    		$page_text .= "<option ".($quiz['quiz_post']==$file?"selected":"")." value='".$file."'>".$file."</option>";
				    	}
				    }
				    $page_text .= "</select>";
		
				    closedir($handle);
				}
				
				$page_text .= "
				<input type='file' class='file ui-widget-content ui-state-default ui-corner-all' name='quiz_post_imageupload' />
			</div>
			
			<div class='fieldset'>
				<div class='legend'><span class='left title'>Teszt kinézete:</span> <span class='ui-icon ui-icon-info help-box left' info-title='Teszt kinézete' info-text='".HELP_QUIZ_QUIZ_THEME."'></span></div>
				<select id='quiz_theme' name='quiz_theme' class='select ui-state-default ui-widget-content ui-corner-all'>
				<option value='none'>Alapértelmezett</option>
					";
					
					foreach ($quiz_theme as $quiz_theme)
					{
						$page_text .= "<option ".($quiz_theme['quiz_theme_id']==$quiz['quiz_theme']?"selected":"")." value='".$quiz_theme['quiz_theme_id']."'>".$quiz_theme['quiz_theme_name']."</option>";
					}
					
					$page_text .= "
				</select>
			</div>
			
			<div class='fieldset'>
				<div class='legend'><span class='left title'>Teszt értékelése:</span> <span class='ui-icon ui-icon-info help-box left' info-title='Teszt értékelése' info-text='".HELP_QUIZ_QUIZ_ERTEKELES."'></span></div>
				<select id='quiz_ertekeles' name='quiz_ertekeles' class='select ui-state-default ui-widget-content ui-corner-all'>
				<option value='none'>Alapértelmezett</option>
					";
					
					foreach ($ertekelesek as $ertekelesek)
					{
						$page_text .= "<option ".($ertekelesek['ertekelesek_id']==$quiz['quiz_ertekeles']?"selected":"")." value='".$ertekelesek['ertekelesek_id']."'>".$ertekelesek['ertekelesek_name']."</option>";
					}
					
					$page_text .= "
				</select>
			</div>
			
			<div class='fieldset'>
				<div class='legend'><span class='left title'>Teszt kérdések:</span> <span class='ui-icon ui-icon-info help-box left' info-title='Teszt kérdések' info-text='".HELP_QUIZ_QUIZ_KERDESEK."'></span></div>
				
				<div id='sortable' class='flexible_ittems'>
					";			
					
					// a képek mappa beolvasása és elraktározása egy változóban
					$folder_upload = IMAGE_UPLOAD.$quiz['quiz_id']."/";
					if ($handle = @opendir($folder_upload))
					{
					
						while (false !== ($file = readdir($handle)))
						{
							if ($file<>"." && $file<>".." && !is_dir($folder_upload."/".$file))
							{
								$folder_files[] = $file;
							}
						}
						
						closedir($handle);
					}
					
					
					// a már felvitt elemek megjelenítése
					foreach ($quiz_ittems as $ittems)
					{
						
						$ittem_id++;
						
						$page_text .= "
							<div class='ittem_wrapper'>
								<label class='left'>Kérdés: </label> <span class='left ui-icon ui-icon-info help-box' info-title='Kérdés' info-text='".HELP_QUIZ_QUIZ_KERDES."'></span>
								<div class='clear'></div>
								
								<input class='text ui-widget-content ui-corner-all' type='text' name='quiz_ittems_title[]' maxlength='100' value='".$ittems['quiz_ittems_title']."' />
								
								
								<label class='left'>Kérdéshez tartozó kép: </label> <span class='left ui-icon ui-icon-info help-box' info-title='Kérdéshez tartozó kép' info-text='".HELP_QUIZ_QUIZ_IMAGEFILE."'></span>
								<div class='clear'></div>
								<a id='news_image_link_".$ittem_id."_link' href='".$folder_upload.$ittems['quiz_ittems_image']."' class='lightbox' ".(empty($ittems['quiz_ittems_image'])?"style='display:none'":"").">
									<img class='ui-corner-all' id='news_image_link_".$ittem_id."' src='".$folder_upload.$ittems['quiz_ittems_image']."' width='100px'>
								</a>
								<br />
								<select id='quiz_image_imagefile_".$ittem_id."' name='quiz_image_imagefile_".$ittem_id."' class='select ui-widget-content ui-state-default ui-corner-all' onChange=\"changeimage('quiz_image_imagefile_".$ittem_id."','news_image_link_".$ittem_id."','".$folder_upload."')\" >
										<option value='none'>Feltöltés</option>";
					
										foreach ($folder_files as $file)
										{
												$page_text .= "<option ".($ittems['quiz_ittems_image']==$file?"selected":"")." value='".$file."'>".$file."</option>";
										}
						$page_text .= "
								</select>
								<input type='file' class='file ui-widget-content ui-state-default ui-corner-all' name='quiz_image_imageupload_".$ittem_id."' />
						";
						
						$answers = unserialize($ittems['quiz_ittems_answers']);
						
						$page_text .= "
								<label class='left'>Válaszok:</label><span class='ui-icon ui-icon-info help-box left' info-title='Válaszok' info-text='".HELP_QUIZ_QUIZ_ITTEMS."'></span>
								<div class='clear'></div>
								<input class='left ui-widget-content ui-corner-all' type='radio' value='0' name='quize_ittems_".$ittem_id."' ".($ittems['quiz_ittems_right']==0?"checked":"")." /><input class='left text ui-widget-content ui-corner-all' type='text' name='quize_ittems_value_".$ittem_id."[]' maxlength='100' value='".$answers[0]."' />
								<div class='clear'></div>
								<input class='left ui-widget-content ui-corner-all' type='radio' value='1' name='quize_ittems_".$ittem_id."' ".($ittems['quiz_ittems_right']==1?"checked":"")." /><input class='left text ui-widget-content ui-corner-all' type='text' name='quize_ittems_value_".$ittem_id."[]' maxlength='100' value='".$answers[1]."' />
								<div class='clear'></div>
								<input class='left ui-widget-content ui-corner-all' type='radio' value='2' name='quize_ittems_".$ittem_id."' ".($ittems['quiz_ittems_right']==2?"checked":"")." /><input class='left text ui-widget-content ui-corner-all' type='text' name='quize_ittems_value_".$ittem_id."[]' maxlength='100' value='".$answers[2]."' />
								<div class='clear'></div>
								<input class='left ui-widget-content ui-corner-all' type='radio' value='3' name='quize_ittems_".$ittem_id."' ".($ittems['quiz_ittems_right']==3?"checked":"")." /><input class='left text ui-widget-content ui-corner-all' type='text' name='quize_ittems_value_".$ittem_id."[]' maxlength='100' value='".$answers[3]."' />
								<div class='clear'></div>
								
							</div>
						";
					}
					
					$page_text .= "
				</div>
			</div>
			
			
			<div class='admin_button'>
				<input type='submit' value='Mentés' class='left ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only'>
				<input id='copyittem_button' type='button' value='Új elem hozzáadása' class='right ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only'>
			</div>
		</form>
	</div>
";

$page_text .= "
<div id='update_string' class='ittem_wrapper' style='display:none'>
	<label class='left'>Kérdés: </label> <span class='left ui-icon ui-icon-info help-box' info-title='Kérdés' info-text='".HELP_QUIZ_QUIZ_KERDES."'></span>
	<div class='clear'></div>
	<input class='text ui-widget-content ui-corner-all' type='text' name='quiz_ittems_title[]' maxlength='100' />
	
	<label class='left'>Kérdéshez tartozó kép: </label> <span class='left ui-icon ui-icon-info help-box' info-title='Kérdéshez tartozó kép' info-text='".HELP_QUIZ_QUIZ_IMAGEFILE."'></span>
	<div class='clear'></div>
	<a id='news_image_link_{ID}_link' href='' class='lightbox' style='display:none'>
		<img class='ui-corner-all' id='news_image_link_{ID}' src='' width='100px'>
	</a>
	<br />
	
	<select id='quiz_image_imagefile_{ID}' name='quiz_image_imagefile_{ID}' class='select ui-widget-content ui-state-default ui-corner-all' onChange=\"changeimage('quiz_image_imagefile_{ID}','news_image_link_{ID}','".$folder_upload."')\" >
		<option value='none' selected='selected'>Feltöltés</option>";

	foreach ($folder_files as $file)
	{
		$page_text .= "<option value='".$file."'>".$file."</option>";
	}
	$page_text .= "
	</select>		
	<input type='file' class='file ui-widget-content ui-state-default ui-corner-all' name='quiz_image_imageupload_{ID}' />

	<label class='left'>Válaszok:</label><span class='ui-icon ui-icon-info help-box left' info-title='Válaszok' info-text='".HELP_QUIZ_QUIZ_ITTEMS."'></span>
	<div class='clear'></div>
	<input class='left ui-widget-content ui-corner-all' type='radio' value='0' name='quize_ittems_{ID}' /><input class='left text ui-widget-content ui-corner-all' type='text' name='quize_ittems_value_{ID}[]' maxlength='100' />
	<div class='clear'></div>
	<input class='left ui-widget-content ui-corner-all' type='radio' value='1' name='quize_ittems_{ID}' /><input class='left text ui-widget-content ui-corner-all' type='text' name='quize_ittems_value_{ID}[]' maxlength='100' />
	<div class='clear'></div>
	<input class='left ui-widget-content ui-corner-all' type='radio' value='2' name='quize_ittems_{ID}' /><input class='left text ui-widget-content ui-corner-all' type='text' name='quize_ittems_value_{ID}[]' maxlength='100' />
	<div class='clear'></div>
	<input class='left ui-widget-content ui-corner-all' type='radio' value='3' name='quize_ittems_{ID}' /><input class='left text ui-widget-content ui-corner-all' type='text' name='quize_ittems_value_{ID}[]' maxlength='100' />
	<div class='clear'></div>
	
</div>
";

// footer js
$footerjs = "
	var ittem_id = ".$ittem_id.";

	$('#copyittem_button').click(function() {
		ittem_id++;
		
		var update_string = $('#update_string').html();
		update_string = update_string.replace(/{ID}/g,ittem_id);
		
		$('#sortable').html($('#sortable').html()+'<div class=\"ittem_wrapper\">'+update_string+'</div>');
		
		render_help_box();
	});
";
			
$theme->footer_jssrc[] = $footerjs;

?>